package com.hyk.commonLib.common.utils.rx.activityResult;

import android.app.Activity;
import android.content.Intent;
import android.os.Parcel;

import androidx.activity.result.ActivityResult;
import androidx.annotation.Nullable;

public class ActivityResultCompat {
    protected int mResultCode;
    protected Intent mData;

    public static ActivityResultCompat convertFromActivityResult(ActivityResult r) {
        return new ActivityResultCompat(r.getResultCode(), r.getData());
    }

    public ActivityResultCompat(int resultCode, Intent data) {
        this.mResultCode = resultCode;
        this.mData = data;
    }


    protected ActivityResultCompat(Parcel in) {
        mResultCode = in.readInt();
        mData = in.readParcelable(Intent.class.getClassLoader());
    }

    public int getResultCode() {
        return mResultCode;
    }

    @Nullable
    public Intent getData() {
        return mData;
    }

    public boolean hasData() {
        return getData() != null;
    }

    public boolean isOk() {
        return getResultCode() == Activity.RESULT_OK;
    }

    public boolean isCanceled() {
        return getResultCode() == Activity.RESULT_CANCELED;
    }

}
